﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DealKhuyenMaiV2.com.Models;
using PagedList;

namespace DealKhuyenMaiV2.com.Controllers
{
    [DealKhuyenMaiV2.com.Controllers.AccountController.AdminAuthorize]
    public class StatusOrderController : BaseController
    {
        //
        // GET: /StatusOrder/

        public ViewResult Index()
        {
            var statusOrders = DbConText.StatusOrders;
            int pageSize = 10;
            ViewBag.Methol = "Index";
            return View(statusOrders.ToList().ToPagedList(1, pageSize));
        }
        [HttpPost]
        public PartialViewResult Index(int? page)
        {
            var statusOrders = DbConText.StatusOrders;
            int pageSize = 10;
            int pageNumber = (page ?? 1);
            ViewBag.Methol = "Index";
            return PartialView("_ListStatusOrders", statusOrders.ToList().ToPagedList(pageNumber, pageSize));
        }
        //
        // GET: /StatusOrder/Details/5

        public ViewResult Details(short id)
        {
            StatusOrder statusorder = DbConText.StatusOrders.Single(s => s.IDStatus == id);
            return View(statusorder);
        }

        //
        // GET: /StatusOrder/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /StatusOrder/Create

        [HttpPost]
        public ActionResult Create(StatusOrder statusorder)
        {
            if (ModelState.IsValid)
            {
                DbConText.StatusOrders.AddObject(statusorder);
                DbConText.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(statusorder);
        }

        //
        // GET: /StatusOrder/Edit/5

        public ActionResult Edit(short id)
        {
            StatusOrder statusorder = DbConText.StatusOrders.Single(s => s.IDStatus == id);
            return View(statusorder);
        }

        //
        // POST: /StatusOrder/Edit/5

        [HttpPost]
        public ActionResult Edit(short id, StatusOrder statusorder)
        {
            StatusOrder _statusorder = DbConText.StatusOrders.Single(s => s.IDStatus == id);
            {
                _statusorder.NameStatus = statusorder.NameStatus;
                _statusorder.Description = statusorder.Description;
            }
            if (ModelState.IsValid)
            {
                DbConText.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(statusorder);
        }

        //
        // GET: /StatusOrder/Delete/5

        //public ActionResult Delete(short id)
        //{
        //    StatusOrder statusorder = DbConText.StatusOrders.Single(s => s.IDStatus == id);
        //    return View(statusorder);
        //}

        ////
        //// POST: /StatusOrder/Delete/5

        //[HttpPost, ActionName("Delete")]
        //public ActionResult DeleteConfirmed(short id)
        //{
        //    StatusOrder statusorder = DbConText.StatusOrders.Single(s => s.IDStatus == id);
        //    DbConText.StatusOrders.DeleteObject(statusorder);
        //    DbConText.SaveChanges();
        //    return RedirectToAction("Index");
        //}

        [HttpPost, ActionName("Delete")]
        public PartialViewResult DeleteConfirmed(int? page, int id)
        {
            StatusOrder statusorder = DbConText.StatusOrders.Single(s => s.IDStatus == id);
            DbConText.StatusOrders.DeleteObject(statusorder);
            DbConText.SaveChanges();

            var statusOrders = DbConText.StatusOrders;
            int pageSize = 10;
            int pageNumber = (page ?? 1);
            ViewBag.Methol = "Index";
            return PartialView("_ListStatusOrders", statusOrders.ToList().ToPagedList(pageNumber, pageSize));

        }
    }
}